package com.example.mqltest.controler;

import com.example.mqltest.Dto.WorkFileDto;
import com.example.mqltest.entity.*;
import com.example.mqltest.service.CourseService;
import com.example.mqltest.service.serviceImp.StudentServiceImp;
import com.example.mqltest.service.serviceImp.TeacherServiceImp;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    CourseService courseService;
    @Autowired
    TeacherServiceImp teacherServiceImp;

    @Autowired
    StudentServiceImp studentService;


    //    查询学生加入的课程
    @GetMapping("/getCourseByStudent")
    public List<Course> getCourseByStudent(@Param("studentId") String studentId) {
        return courseService.getCourseByStudent( studentId );
    }
    //    查询教师管理的课程
    @GetMapping("/getCourseByTeacher")
    public List<Course> getCourseByTeacher(@Param("teacherId") String teacherId) {
        return courseService.getCourseByTeacher( teacherId );
    }

    //    创建课程
    @RequestMapping("/createCourse")
    public Result createCourse(@RequestBody Course course) {

        return courseService.createCourse( course );
    }

    //归档
    @GetMapping("/archiveCourse")
    public Result archiveCourse(@Param("code") String code,@Param("studentId")String studentId,@Param( "teacherId" ) String teacherId,@Param( "archiveStatus" ) String archiveStatus){
        return courseService.archiveCourse(code,studentId,teacherId,archiveStatus);
    }
    //获取学生的某个作业上传的文件
    @GetMapping( "/getWorkFileByStudent" )
    public List<WorkFileDto> getWorkFileByStudent(@Param( "studentId" )String studentId,@Param( "workId" )int workId){
        return courseService.getWorkFileByStudent(studentId,workId);
    }

    //通过Id获取作业详情
    @GetMapping("/getWorkById")
    public Work getWorkById(@Param("workId")int workId){
        return  courseService.getWorkById(workId);
    }
    //删除文件
    @GetMapping("/deleteWorkFile")
    public Result deleteWorkFile(@Param("fileId") int fileId){
        return courseService.deleteWorkFile(fileId);
    }
    @GetMapping("/updateWorkStatus")
    public void updateWorkStatus(@Param("studentId")String studentId,@Param("workId")int workId,@Param( "status")String status,@Param( "date" ) Date date){
        courseService.studentUpdateWorkStatus( studentId,workId,status,date );
    }
    //获取所有学生作业情况，进行查看批改
    @GetMapping("/getStudentWorkById")
    public List<StudentWork> getStudentWorkById(@Param( "workId" )int workId){
        return courseService.getStudentWorkById( workId );
    }

    //获取所有的作业
    @GetMapping("/getAllWorksByCode")
    public List<Work> getAllWorksByCode(@Param( "code" )String code){
        return courseService.getAllWorksByCode(code);
    }

    //获取当前作业的某个学生的作业情况
    @GetMapping("/getStudentWork")
    public WorkList getStudentWork(@Param( "workId" )int workId,@Param( "studentId" )String studentId){
        return courseService.getStudentWork(workId,studentId);
    }

}

